-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #323 from Lumiwealth/yahoo-last-price-fix
bug fix for yahoo get last price (it was getting the price from the d…
- Loading branch information
Showing
5 changed files
with
100 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="lumibot", | ||
version="2.9.2", | ||
version="2.9.3", | ||
author="Robert Grzesik", | ||
author_email="[email protected]", | ||
description="Backtesting and Trading Library, Made by Lumiwealth", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import datetime | ||
|
||
from lumibot.backtesting import BacktestingBroker, YahooDataBacktesting | ||
from lumibot.strategies import Strategy | ||
from lumibot.traders import Trader | ||
|
||
|
||
class YahooPriceTest(Strategy): | ||
parameters = { | ||
"symbol": "SPY", # The symbol to trade | ||
} | ||
|
||
def initialize(self): | ||
# There is only one trading operation per day | ||
self.sleeptime = "1D" | ||
|
||
def on_trading_iteration(self): | ||
# Get the parameters | ||
symbol = self.parameters["symbol"] | ||
|
||
# Get the datetime | ||
self.dt = self.get_datetime() | ||
|
||
# Get the last price | ||
self.last_price = self.get_last_price(symbol) | ||
|
||
|
||
class TestYahooBacktestFull: | ||
def test_yahoo_last_price(self): | ||
""" | ||
Test the YahooDataBacktesting class by running a backtest and checking that the strategy object is returned | ||
along with the correct results | ||
""" | ||
# Parameters: True = Live Trading | False = Backtest | ||
# trade_live = False | ||
backtesting_start = datetime.datetime(2023, 11, 1) | ||
backtesting_end = datetime.datetime(2023, 11, 2) | ||
|
||
data_source = YahooDataBacktesting( | ||
datetime_start=backtesting_start, | ||
datetime_end=backtesting_end, | ||
) | ||
|
||
broker = BacktestingBroker(data_source=data_source) | ||
|
||
poly_strat_obj = YahooPriceTest( | ||
broker=broker, | ||
backtesting_start=backtesting_start, | ||
backtesting_end=backtesting_end, | ||
) | ||
|
||
trader = Trader(logfile="", backtest=True) | ||
trader.add_strategy(poly_strat_obj) | ||
results = trader.run_all(show_plot=False, show_tearsheet=False, save_tearsheet=False) | ||
|
||
assert results | ||
|
||
last_price = poly_strat_obj.last_price | ||
# Round to 2 decimal places | ||
last_price = round(last_price, 2) | ||
|
||
assert last_price == 419.20 # This is the correct price for 2023-11-01 (the open price) |