This project is on Windows 11 64x. And it's OK for All Windows.
This guide provides instructions on how to install TA-Lib on a Windows system using Visual Studio. You may get an error if you don't do it, this is because the ta-lib (which is neccessary to vnpy) is for 32-bit systems and is not compatible with 64-bit.
- Download and unzip
ta-lib-0.4.0-msvc.zip. You can find it here. - Visual Studio Community with the Visual C++ feature enabled. Ensure this is checked during installation.
- Set Up TA-Lib:
- Extract the
ta-libfolder and place it at the root of your C: drive.
- Extract the
- Build TA-Lib:
- Open the
Native Tools Command Promptfor Visual Studio.
- Navigate to the TA-Lib source directory by entering:
```
cd /d C:\ta-lib\c\make\cdr\win32\msvc
```
- Build the library by running:
```
nmake
```
- Open the
-
I have Modified
requirements.txt:- I have added several modules like
vnpy_ctastrategy,vnpy_ctabacktester, andvnpy_sqlite,andvnpy_datamanager,e.t.c tovnpy-3.9.1/requirements.txt.So this step you can skip. Or you may pip install them. - In the original
vnpy-3.9.1/requirements.txtin vnpy GitHub repository, they are missing and you need to add them.
- I have added several modules like
-
Install vnpy:
- Navigate to the
vnpy-3.9.1directory. - Run the installation batch file:
install.bat - To start vnpy, use:
cd .. python run.py
- Navigate to the
This setup will launch vnpy, ready for use. Then a window will pop up.

For more detailed information, please refer to the official vnpy GitHub repository.
This project implements and tests two advanced trading strategies using the VeighNa Trader platform:
- Kalman Filter Strategy
- AC (Actor-Critic) LSTM Strategy
See all my code in train_ac.ipynb and folder strategies.
pip install yfinance pykalman torch==2.1.0+cu121Register a SimNow account and follow the documentation to connect to the CTP interface.
Use the yfinance library to download stock data for Alibaba (BABA).
import yfinance as yf
ticker = 'BABA'
start_date = "2012-01-01"
end_date = "2024-05-01"
data = yf.download(ticker, start=start_date, end=end_date)
data.to_csv(f'{ticker}_stock_data.csv')Import the downloaded data into the VeighNa Trader platform. Ensure that the column names match the expected format. You can do this manually or by editing the CSV file.
### 5. Kalman Filter Strategy The Kalman Filter strategy is implemented in `kalman_strategy.py`. Place this file in the appropriate directory:C:\Users\YOUR_USER\strategies
Or in your Python packages directory (e.g., C:\Users\YOUR_USER\AppData\Roaming\Python\Python310\site-packages\vnpy_ctastrategy\strategies)
The AC LSTM strategy is implemented in ac_lstm_strategy.py. Ensure to modify the model loading path in the strategy file to match your environment.
self.model_path = 'path_to_your_model\ac_lstm_model.pth'Train the AC LSTM model using the scripts/train_ac.ipynb notebook or scripts/train_ac.py.
# Example parameters
csv_file = '../data/BABA_stock_data.csv'
model_path = '../saved_models/ac_lstm_model.pth'
loss_file_path = '../saved_models/ac_loss_record.csv'
input_dim = 5
hidden_dim = 128
action_dim = 3
learning_rate = 1e-4
num_epochs = 150
seq_length = 30
dataset = StockDataset(csv_file, seq_length=seq_length, end_date='2021-06-06')
sampler = SequentialSampler(dataset)
batch_sampler = BatchSampler(sampler, batch_size=32, drop_last=False)
dataloader = DataLoader(dataset, batch_sampler=batch_sampler)
model = ActorCritic(input_dim, hidden_dim, action_dim)
optimizer = optim.Adam(model.parameters(), lr=learning_rate)
train_ac(model, dataloader, optimizer, num_epochs, model_path, loss_file_path)To run backtests, follow these steps:
Click on CTA Backtesting in the main menu.
Select the desired strategy (e.g., AC_LSTM_Strategy, KalmanFilterStrategy).
Choose the local data corresponding to your imported data (e.g., .NYSE).
Set the start and end dates for the backtest.

In conclusion, while default strategies like AtrRsiStrategy and TurtleSignalStrategy hovered around 0% returns, the Kalman Filter strategy achieved an annual return of 20%, and the LSTM Actor-Critic model demonstrated even more impressive results.
Browse the 21300180048杜楷劼_程序设计_期末大作业.pdf for more details.
- CTA Strategy Documentation
- VN.py GitHub Repository
- VN.py Documentation
- VN.py 2.9 中文手册 - Part 1
- VN.py 2.9 中文手册 - Part 2
This project is licensed under the MIT License - see the LICENSE.md file for details.






