pep8 conversion of python algos (#7942)

* pep8 conversion of python algos

* adding 10 more pep8 converted algos
This commit is contained in:
Ashutosh
2024-04-18 23:44:56 +05:30
committed by GitHub
parent ed351c8726
commit 1cae47ab25
15 changed files with 363 additions and 360 deletions
@@ -17,46 +17,46 @@ from AlgorithmImports import *
### Regression algorithm which tests that a two leg currency conversion happens correctly
### </summary>
class TwoLegCurrencyConversionRegressionAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 4, 4)
self.SetEndDate(2018, 4, 4)
self.SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash)
def initialize(self):
self.set_start_date(2018, 4, 4)
self.set_end_date(2018, 4, 4)
self.set_brokerage_model(BrokerageName.GDAX, AccountType.CASH)
# GDAX doesn't have LTCETH or ETHLTC, but they do have ETHUSD and LTCUSD to form a path between ETH and LTC
self.SetAccountCurrency("ETH")
self.SetCash("ETH", 100000)
self.SetCash("LTC", 100000)
self.SetCash("USD", 100000)
self.set_account_currency("ETH")
self.set_cash("ETH", 100000)
self.set_cash("LTC", 100000)
self.set_cash("USD", 100000)
self._ethUsdSymbol = self.AddCrypto("ETHUSD", Resolution.Minute).Symbol
self._ltcUsdSymbol = self.AddCrypto("LTCUSD", Resolution.Minute).Symbol
self._eth_usd_symbol = self.add_crypto("ETHUSD", Resolution.MINUTE).symbol
self._ltc_usd_symbol = self.add_crypto("LTCUSD", Resolution.MINUTE).symbol
def OnData(self, data):
if not self.Portfolio.Invested:
self.MarketOrder(self._ltcUsdSymbol, 1)
def on_data(self, data):
if not self.portfolio.invested:
self.market_order(self._ltc_usd_symbol, 1)
def OnEndOfAlgorithm(self):
ltcCash = self.Portfolio.CashBook["LTC"]
def on_end_of_algorithm(self):
ltc_cash = self.portfolio.cash_book["LTC"]
conversionSymbols = [x.Symbol for x in ltcCash.CurrencyConversion.ConversionRateSecurities]
conversion_symbols = [x.symbol for x in ltc_cash.currency_conversion.conversion_rate_securities]
if len(conversionSymbols) != 2:
if len(conversion_symbols) != 2:
raise ValueError(
f"Expected two conversion rate securities for LTC to ETH, is {len(conversionSymbols)}")
f"Expected two conversion rate securities for LTC to ETH, is {len(conversion_symbols)}")
if conversionSymbols[0] != self._ltcUsdSymbol:
if conversion_symbols[0] != self._ltc_usd_symbol:
raise ValueError(
f"Expected first conversion rate security from LTC to ETH to be {self._ltcUsdSymbol}, is {conversionSymbols[0]}")
f"Expected first conversion rate security from LTC to ETH to be {self._ltc_usd_symbol}, is {conversion_symbols[0]}")
if conversionSymbols[1] != self._ethUsdSymbol:
if conversion_symbols[1] != self._eth_usd_symbol:
raise ValueError(
f"Expected second conversion rate security from LTC to ETH to be {self._ethUsdSymbol}, is {conversionSymbols[1]}")
f"Expected second conversion rate security from LTC to ETH to be {self._eth_usd_symbol}, is {conversion_symbols[1]}")
ltcUsdValue = self.Securities[self._ltcUsdSymbol].GetLastData().Value
ethUsdValue = self.Securities[self._ethUsdSymbol].GetLastData().Value
ltc_usd_value = self.securities[self._ltc_usd_symbol].get_last_data().value
eth_usd_value = self.securities[self._eth_usd_symbol].get_last_data().value
expectedConversionRate = ltcUsdValue / ethUsdValue
actualConversionRate = ltcCash.ConversionRate
expected_conversion_rate = ltc_usd_value / eth_usd_value
actual_conversion_rate = ltc_cash.conversion_rate
if actualConversionRate != expectedConversionRate:
if actual_conversion_rate != expected_conversion_rate:
raise ValueError(
f"Expected conversion rate from LTC to ETH to be {expectedConversionRate}, is {actualConversionRate}")
f"Expected conversion rate from LTC to ETH to be {expected_conversion_rate}, is {actual_conversion_rate}")