@@ -39,21 +39,68 @@ pip install TrendMaster
3939Here's how to integrate TrendMaster into your Python projects:
4040
4141``` python
42- from trendmaster import TrendMaster
43-
44- # Initialize TrendMaster
45- test_symbol = ' SBIN'
46- tm = TrendMaster(symbol_name_stk = test_symbol)
47-
48- # Load data
49- data = tm.load_data(symbol = test_symbol)
50-
51- # Train the model
52- tm.train(test_symbol, transformer_params = {' epochs' : 1 })
53-
54- # Perform inference
55- predictions = tm.inferencer.predict_future(val_data = data, future_steps = 100 , symbol = test_symbol)
56- print (predictions)
42+ # Example usage of merged_module.py
43+
44+ from trendmaster import (
45+ DataLoader,
46+ TransAm,
47+ Trainer,
48+ Inferencer,
49+ set_seed,
50+ plot_results,
51+ plot_predictions
52+ )
53+
54+ import pyotp
55+
56+ # Set seed for reproducibility
57+ set_seed(42 )
58+
59+ user_id = ' YOUR_ZERODHA_USER_ID'
60+ password = ' YOUR_ZERODHA_PASSWORD' # Replace with your password
61+ totp_key = ' YOUR_ZERODHA_2FA_KEY' # Replace with your TOTP secret key
62+
63+ # Generate the TOTP code for two-factor authentication
64+ totp = pyotp.TOTP(totp_key)
65+ twofa = totp.now()
66+
67+ # Initialize DataLoader and authenticate
68+ data_loader = DataLoader()
69+ kite = data_loader.authenticate(user_id = user_id, password = password, twofa = twofa)
70+
71+ # Prepare data
72+ train_data, test_data = data_loader.prepare_data(
73+ symbol = ' RELIANCE' ,
74+ from_date = ' 2023-01-01' ,
75+ to_date = ' 2023-02-27' ,
76+ input_window = 30 ,
77+ output_window = 10 ,
78+ train_test_split = 0.8
79+ )
80+ import torch
81+ # Initialize model, trainer, and train the model
82+ device = torch.device(' cuda' if torch.cuda.is_available() else ' cpu' )
83+ print (f ' Training of { device} device. ' )
84+ model = TransAm(num_layers = 2 , dropout = 0.2 ).to(device)
85+
86+ trainer = Trainer(model, device, learning_rate = 0.001 )
87+ train_losses, val_losses = trainer.train(train_data, test_data, epochs = 2 , batch_size = 64 )
88+
89+ # Save the trained model
90+ trainer.save_model(' transam_model.pth' )
91+
92+ # Initialize inferencer and make predictions
93+ inferencer = Inferencer(model, device, data_loader)
94+ predictions = inferencer.predict(
95+ symbol = ' RELIANCE' ,
96+ from_date = ' 2023-02-27' ,
97+ to_date = ' 2023-12-31' ,
98+ input_window = 30 ,
99+ future_steps = 10
100+ )
101+
102+ # Evaluate the model
103+ test_loss = inferencer.evaluate(test_data, batch_size = 32 )
57104```
58105
59106## 📊 Sample Results
0 commit comments