WEBVTT

00:00.120 --> 00:05.360
So the other thing to show you the bigger change is a new class called Trading Floor.

00:05.360 --> 00:06.720
And it's really simple.

00:06.760 --> 00:08.200
It's this is all it is.

00:08.400 --> 00:13.760
And this represents our our set of traders, our three traders.

00:13.880 --> 00:14.600
We're not using that.

00:14.640 --> 00:15.320
So we'll take that out.

00:15.320 --> 00:17.400
We're not not using agents at all here.

00:17.720 --> 00:19.720
Um, so here's how it works.

00:19.960 --> 00:24.840
Uh, it has a, a function here called traders that, that returns a list of traders.

00:24.840 --> 00:26.720
And they are Alice, Bob and Carol.

00:27.120 --> 00:32.880
Alice and Carol are using deep seek, and Bob is just using Gpt4 and mini, which is the default.

00:33.120 --> 00:34.280
And so this just returns.

00:34.320 --> 00:36.000
Alice, Bob and Carol ABC.

00:36.680 --> 00:43.880
Uh, and then this, this is the, uh, this is the main this is the business, uh, async def run every

00:43.880 --> 00:44.920
30 minutes.

00:45.200 --> 00:47.880
Uh, and it's just an infinite loop.

00:47.880 --> 00:50.280
And it says while for while true.

00:50.280 --> 00:53.040
So it goes on forever for trader in traders.

00:53.400 --> 01:00.120
Uh, and then it just runs the trader, which you remember flips between trading and rebalancing.

01:00.120 --> 01:03.360
And then it goes to sleep for half an hour and then it will repeat.

01:03.520 --> 01:05.640
And I need to add an exception handler in here.

01:05.740 --> 01:10.100
Otherwise, any time that any of the anything goes awry with our agents, it will just stop.

01:10.100 --> 01:11.460
So I'm sure I will do that.

01:11.460 --> 01:12.460
I'll have some more.

01:12.620 --> 01:15.980
Some more, uh, belt and braces by the time that you see this.

01:15.980 --> 01:17.820
Or you can add on some more stuff to.

01:17.980 --> 01:20.740
And it would be good to have some various guardrails in here.

01:20.940 --> 01:22.540
Um, but that's fine for now.

01:22.540 --> 01:28.660
And having a time.sleep in your code is generally frowned upon in normal Python, because that would

01:28.660 --> 01:30.300
be holding things up.

01:30.300 --> 01:35.420
But when you're using Asyncio, this is this is considered a perfectly decent, uh, and it means,

01:35.420 --> 01:39.980
of course, that it's not not going to be working at this point, but it will be, uh, giving up for

01:39.980 --> 01:44.860
any other for the event loop to run anything else that was awaiting at the time.

01:45.540 --> 01:48.740
Uh, and so this is just something that runs.

01:49.020 --> 01:56.180
And this brings me to saying that the way that you run this is you simply bring up a terminal and then

01:56.180 --> 02:00.380
you do you've run trading Pi to set the trading floor going.

02:00.620 --> 02:01.660
And that's what we'll do.

02:01.660 --> 02:05.260
So you remember that it's control and backtick to bring up a terminal.

02:05.300 --> 02:06.180
Here it comes.

02:06.660 --> 02:09.900
And now we go into the sixth folder and now we type.

02:09.940 --> 02:22.250
You've run trading floor.py and off it goes and it will start doing stuff and you'll see it doing things

02:22.250 --> 02:30.250
as it goes, as it's reading stuff in and doing things and starting to work at making trading decisions.

02:30.690 --> 02:37.610
And so we will this leave this running as it does its thing, while I bring you over to the last thing

02:37.650 --> 02:38.570
to show you.

02:38.570 --> 02:42.450
And of course, the last thing is a gradio user interface.

02:42.850 --> 02:46.370
And now look that, you know, the the purpose of this course is not user interfaces.

02:46.370 --> 02:50.970
So I'm not going to go through this in much detail other than to point out a few things that are quite

02:51.010 --> 02:52.170
satisfactory.

02:53.010 --> 02:59.370
I've got in here a model class called Trader View, which is just used to be like a user interface sort

02:59.370 --> 03:07.210
of control class that sits between the UI and the business logic, and it holds a trader underneath

03:07.210 --> 03:11.410
it, so it holds one of either Alice or Bob or Carol.

03:11.410 --> 03:15.990
And we're going to have three parts of the user interface, one for each of our traders, and there

03:15.990 --> 03:19.310
will be a trader view created for each of those three.

03:19.710 --> 03:25.870
And the trader view is going to be responsible for returning each of the bits of information that will

03:25.870 --> 03:29.070
populate different parts of the user interface, as you will see.

03:29.430 --> 03:32.910
And there is, for example, a chart to show the value of the portfolio.

03:33.190 --> 03:36.670
There's some stuff to organize that chart.

03:36.710 --> 03:42.430
There's something that shows the current holdings in the portfolio and various other bits and pieces.

03:42.830 --> 03:48.150
The balance, the PNL and then then all of these components get, get returned.

03:48.510 --> 03:51.710
And then there is agent UI component.

03:51.710 --> 03:55.590
This is the user interface that goes alongside this trader view.

03:55.630 --> 03:59.110
This is a user interface that represents one of our three traders.

03:59.110 --> 04:05.910
And again you know, the knowing how to make nice gradio UIs comes comes with some practice and is not

04:05.910 --> 04:07.070
particularly part of this course.

04:07.070 --> 04:09.190
But do take a look at it if you're interested.

04:09.550 --> 04:14.830
Um, and then the thing that, that it all comes down to are these callback functions.

04:14.830 --> 04:22.220
That's what what, uh, gradio is so powerful at, uh, and the callback functions is where the user

04:22.220 --> 04:25.340
interface is able to call in to get various things to happen.

04:25.940 --> 04:32.380
And then yeah, this this just shows that if there's a run button, if it's clicked, it will call run

04:32.420 --> 04:33.340
all agents.

04:33.460 --> 04:35.940
The inputs are all of the states of the agents.

04:35.940 --> 04:39.300
The outputs are all of the components that they need to be displayed in.

04:39.300 --> 04:44.020
So Gradio automatically hooks up the inputs with the outputs of this function.

04:44.020 --> 04:45.180
Run all agents.

04:45.620 --> 04:50.100
The refresh button refreshes the UI it calls UI refresh.

04:50.260 --> 04:52.940
Again, all of the inputs are hooked up to the states.

04:52.980 --> 04:55.220
All of the outputs are hooked up to the components.

04:55.500 --> 04:58.420
When you load the user interface, it will start doing this.

04:58.460 --> 05:04.180
It will start painting the UI, and then it also has a timer that runs to refresh the user interface

05:04.180 --> 05:09.980
every half an hour, so that any time that there's been trading activity, you should shortly afterwards

05:10.020 --> 05:11.860
see that appearing on the user interface.

05:12.060 --> 05:13.260
And that's all there is to it.

05:13.260 --> 05:14.100
That's the UI.

05:14.220 --> 05:15.820
I think it's time that we see it.

05:15.820 --> 05:17.100
So look to set your expectations.

05:17.100 --> 05:21.940
This is still an early version of our autonomous trading platform, and I intend to keep working on

05:21.940 --> 05:22.100
it.

05:22.100 --> 05:26.400
And so you should bring it up as it is right now, because I bet by the time you get here and you're

05:26.400 --> 05:29.240
trying this, I will have made the UI even better.

05:29.240 --> 05:30.720
And it's going to be worth checking out.

05:30.720 --> 05:34.120
But this is the version I have as of now for your your critique.

05:34.480 --> 05:37.760
Uh, we go into the sixth folder and we type.

05:40.200 --> 05:41.080
App dot.

05:42.400 --> 05:44.520
Uh, and that should be it.

05:45.000 --> 05:48.240
And with that it's going to initialize our Gradio app.

05:48.240 --> 05:49.800
And up it comes.

05:49.840 --> 05:52.040
And the first thing it has to do is Alice.

05:52.040 --> 05:58.120
Bob and Carol need to connect the MCP servers and read their accounts and set themselves up.

05:58.160 --> 05:59.920
And while they are doing that, I will flip over.

05:59.960 --> 06:06.000
It takes about 30s, but I did it already a minute ago and here is what appears when it's done.

06:06.360 --> 06:12.760
And you can see the three traders appearing Alice, Bob and Carol in our trading floor simulator.

06:12.800 --> 06:14.720
You can see the activity down there.

06:15.040 --> 06:18.440
Uh, you can see their strategies, which will evolve over time.

06:18.440 --> 06:23.280
You can see the rather sorry state of affairs that even though this is just from very recently, already

06:23.280 --> 06:25.640
all three traders are in the red right now.

06:25.760 --> 06:28.240
But it has been a terrible day in markets.

06:28.480 --> 06:32.180
Uh, and there's some sort of a graph that's showing the change in position.

06:32.180 --> 06:36.580
It's just this is only since I kicked it off, I reset just just like an hour ago.

06:36.580 --> 06:39.660
So we're not we're not seeing much activity yet.

06:39.900 --> 06:41.540
These are small changes.

06:41.740 --> 06:46.820
And if I scroll down we see against each trader their holdings in terms of the stock symbol and how

06:46.820 --> 06:48.740
much they have in their portfolio.

06:48.860 --> 06:54.100
And then below that, you've got all of the transactions listed down there, along with the rationale

06:54.100 --> 06:56.540
of why they made the transaction that they did.

06:56.740 --> 07:03.020
And then at the bottom are buttons to refresh everything as of right now, or to ask the traders to

07:03.060 --> 07:03.540
trade.

07:03.540 --> 07:07.380
Right now they are trading every half an hour, of course, in the trading floor.

07:07.420 --> 07:12.860
But you can also kick off a trade right now by pressing that button and it will go off and do its thing,

07:12.980 --> 07:14.380
um, as we had done in the lab.

07:14.380 --> 07:20.020
And of course, if we flip over here, uh, this has, has uh, has already refreshed and these axes

07:20.020 --> 07:21.540
start at 0 to 1000.

07:21.540 --> 07:28.180
But actually if you resize it, it shows it to be just, just the, uh, the sort of $5 differences.

07:28.580 --> 07:31.860
Um, so that is the user interface.

07:31.860 --> 07:34.580
And it's a lot of fun if you ask me.

07:34.580 --> 07:37.570
And this is something that you can just leave running.

07:37.570 --> 07:42.450
And while I was building this, I'd leave it running for long periods of time and in different market

07:42.450 --> 07:42.970
conditions.

07:42.970 --> 07:44.690
You will see things changing.

07:44.810 --> 07:50.250
And of course, I should turn my phone off silent, because there will indeed be pings coming through

07:50.730 --> 07:51.650
as trades happen.

07:51.690 --> 07:57.770
I can I can show you some of the notifications that I've had, um, or I've had I've had a lot of notifications

07:57.770 --> 08:03.290
because this has been running uh, there they all are executed trades executed, trades executed trades

08:03.290 --> 08:08.930
with, with uh, the summaries and with the current portfolio and with all of them reporting their slight

08:08.930 --> 08:09.610
loss.

08:09.850 --> 08:12.250
Uh, it's very entertaining.

08:12.250 --> 08:13.450
It's very exciting.

08:13.490 --> 08:18.650
It's it's truly autonomous that these are making their own decisions.

08:18.650 --> 08:24.170
And I can't wait to leave these over a long period of time and see what happens.

08:24.210 --> 08:28.610
I mean, first and foremost, whether they actually make money or not, uh, but also to whether their

08:28.610 --> 08:36.010
strategy evolves, whether the memory starts to build from the researcher and exactly how the situation

08:36.010 --> 08:37.050
transpires.

08:37.050 --> 08:38.770
Because I just don't know.

08:38.810 --> 08:40.490
And that is the joy of it.
