Open QueRicoChulo opened 6 months ago
@QueRicoChulo I will be standing on the sidelines watching for the resolution as this is my first GitHub experience. May I ask, which algorithm from Lumibot are you coding for ticker SPY (good idea to automate that) then API your app to Alpaca to run with your broker... right?
@QueRicoChulo Aye yo, I pasted and ran the code into Colab Notebook there were no errors....
@QueRicoChulo Aye yo, I pasted and ran the code into Colab Notebook there were no errors....
well in the Testing of the original code that the writer coded. The amount of Paper money was decreasing and increasing during the test. I dont know how to as of yet read the logs too well, I am also wondering if there is a way to put more than one symbol to trade in the code, also about the sentiment part with the news. Does that have to be defined differently depending on what the symbol being traded is? Example if trading Harley Davidson. Would the news need to be defined differently?
@QueRicoChulo That's a good question about changing market news on sentiment analysis give me a day to review. As for the first issue I am very new to Python though after just 2 hours and 40 pages of notes and a quick search on [StackOver Flow] we would have to add a FUNCTION into the script. Once defined, Python functions can be called multiple times and from any location in a program. Do you know how? I will try to write a script this afternoon...here is what I got so far.
stocks = ('AAPL', 'GOOGL', 'YHOO', 'MSFT', 'AMZN', 'DAI')
@QueRicoChulo Currently, the script is for SPY. Do we know what the source of the market data is ? It says Yahoo Back testing.... was not aware Yahoo offered Quant Fin/ML back testing. Lumibot gave the strategy but do we know which strategy?
@QueRicoChulo Currently, the script is for SPY. Do we know what the source of the market data is ? It says Yahoo Back testing.... was not aware Yahoo offered Quant Fin/ML back testing. Lumibot gave the strategy but do we know which strategy?
strategy was one my friend who is a stock trader had suggested to me so I added it. The Code breaks down like this
Imports and Setup: The script starts by importing necessary libraries and modules, setting up the API connection with Alpaca for trading and YahooDataBacktesting for data.
Strategy Definition (MLTrader):
Trading Logic (on_trading_iteration):
Backtesting Setup:
Real-Time Trading Execution:
This trading strategy utilizes a combination of technical indicators (ATR for risk management) and sentiment analysis (news impact) to make trading decisions. The use of bracket orders for trade management helps to automatically secure profits and limit losses, crucial for effective risk management in trading.
@QueRicoChulo That's a good question about changing market news on sentiment analysis give me a day to review. As for the first issue I am very new to Python though after just 2 hours and 40 pages of notes and a quick search on [StackOver Flow] we would have to add a FUNCTION into the script. Once defined, Python functions can be called multiple times and from any location in a program. Do you know how? I will try to write a script this afternoon...here is what I got so far. #For example stocks = ('AAPL', 'GOOGL', 'YHOO', 'MSFT', 'AMZN', 'DAI')
symbol in place of STOCKS?
I am new to this and coding. I made a couple mods to the file so I would like someone to review it and help me where it needs help please and please adapt if you think its a good idea....
your patience is appreciated
Danny
from lumibot.brokers import Alpaca from lumibot.backtesting import YahooDataBacktesting from lumibot.strategies.strategy import Strategy from lumibot.traders import Trader from datetime import datetime from alpaca_trade_api import REST from timedelta import Timedelta from finbert_utils import estimate_sentiment
import numpy as np #added to get pythons math functions
API_KEY = "YOUR API KEY" API_SECRET = "YOUR API SECRET" BASE_URL = "https://paper-api.alpaca.markets"
ALPACA_CREDS = { "API_KEY":API_KEY, "API_SECRET": API_SECRET, "PAPER": True }
class MLTrader(Strategy): def initialize(self, symbol:str="SPY", cash_at_risk:float=.5): self.symbol = symbol self.sleeptime = "24H" self.last_trade = None self.cash_at_risk = cash_at_risk self.api = REST(base_url=BASE_URL, key_id=API_KEY, secret_key=API_SECRET)
start_date = datetime(2020,1,1) end_date = datetime(2023,12,31) broker = Alpaca(ALPACA_CREDS) strategy = MLTrader(name='mlstrat', broker=broker, parameters={"symbol":"SPY", "cash_at_risk":.5}) strategy.backtest( YahooDataBacktesting, start_date, end_date, parameters={"symbol":"SPY", "cash_at_risk":.5} )
trader = Trader()
trader.add_strategy(strategy)
trader.run_all()