Jane_D
(Jane D)
August 11, 2022, 3:33am
1
I dot get why Im getting this error. Its a simple synthax error it seems
Code
Import libraries
import numpy as np
import pandas as pd
import statsmodels.api as sm
from pykalman import KalmanFilter
from numpy import log, polyfit, sqrt, std, subtract
Import blueshift libraries
from blueshift.pipeline import Pipeline
from blueshift.api import(
symbol,
order_target_percent,
schedule_function,
date_rules,
time_rules,
attach_pipeline,
pipeline_output,
get_datetime
)
def make_strategy_pipeline(context):
"""
A function to make the pipeline.
"""
pipe = Pipeline()
return pipe
def initialize(context):
context.lookback = 45
attach_pipeline(make_strategy_pipeline(context), name='strategy_pipeline')
Rebalance every day
schedule_function(rebalance,
date_rules.every_day(),
time_rules.market_open(hours=0, minutes=1))
def rebalance(context, data):
Get the pipeline results
pipeline_results = pipeline_output('strategy_pipeline')
Exclude the SPY ETF
#exclude_tickers = symbol('SPY')
Get the data for the pipeline output
try:
data = data.history(
pipeline_results.index, 'close', context.lookback, '1d')
except IndexError:
return
data.dropna(inplace=True, axis='columns')
data2 = data['Crypto(BTC/USDT [3])']
print("data2",data2.to_string())
Hi Jane,
The reason for the error is that you’re using a string. You have to use the symbol function instead.
You can read more about this here .
You can use the following line of code:
data2 = data[symbol("BTC/USDT")]
print(data2)
Hope this helps!
Thanks,
Bhavika
Jane_D
(Jane D)
August 12, 2022, 2:40pm
3
Is there a way to convert Crypto(BTC/USDT [3]) to symbol("BTC/USDT") programmatically?
Hi Jane,
I am not exactly clear about your requirement. Since you asked, it can be done with an if-else statement but you will have to write a method for the same. But as I said, I am not exactly sure about the need for doing the same.
Thanks,
Akshay
Jane_D
(Jane D)
October 22, 2022, 2:44pm
5
When I get the column names its like this:
Crypto(BTC/USDT [3])
I would like it changed to symbol("BTC/USDT")
Im wondering how to get it done programatically.
Hi Jane,
You can directly access the columns using symbol("BTC/USDT") .
For example:
context.long_portfolio = [symbol('BTC/USDT'), symbol('BTC/USD')]
price_data = data.history(context.long_portfolio, 'close', 10, '1d')
Let's say you have a portfolio like the one shown above.
Though the column names when you print the price data would be displayed like Crypto(BTC/USDT [3]). But if you want to access the columns, you can do so by:
price_data[symbol('BTC/USDT')]
Hope this helps!
Thanks,
Akshay