Quantopian & Finance Flashcards
Quantopian: What does the initialize function do?
The initialize function runs once when the script starts.
It takes in one parameter which is context.
Context is a python dictionary that stores a bunch of data on your strategy (your protfolio, your performace, leverage, other info about you, etc).
When using quantopian the initialize function needs to be defined but it does not need to be called in the script.
Quantopian: what is the history() method and what are its input parameters?
The history() module returns the price (or volume, etc) for the specified asset for x time back depending on the bar_count and frequency chosen.
Note: that the module is based on a pandas dataframe.
Input parameters: asset (e.g. the stock), field (type of data, price or volume?), bar_count (how many bars do you want), frequency (time period).
Quantopian: How can you pull price data?
you can get price data using data.history()
Finance: What does alpha represent?
Alpha represents the performance of a portfolio relative to a benchmark.
In other words, alpha is a measure of the return on investment that is not a result of general movement in the market.
Finance: What is beta?
Beta is a measurement of the volatility of an asset’s returns.
It is used as a measurement of risk.
A higher beta means greater risk, but also greater expected returns.
β = 1, exactly as volatile as the market.
β > 1, more volatile than the market.
β < 1 > 0, less volatile than the market.
β = 0, uncorrelated to the market.
β < 0, negatively correlated to the market.
Quantopian: How do you run your own function in quantopian?
Using schedule_function() written under initialize function.
You need to place your function as a parameter within schedule_function().
You can also define how often it runs, hourly, weekly, monthly, etc.
Also, when it runs relative to the market open. For example, you can make it offset so that it only runs 1 hour after the market opens.
What does the blaze ecosystem allow for?
It provides python users high-level access to efficient computation on inconveniently large data.
Qunatopian: what does blaze.compute() do?
It returns a pandas dataframe from a blaze.
What should you always remember about applying functions to dataframes in quantopian?
You need to use pipeline.
Applying functions to dataframes outside out pipeline is going to be a lot slower.
How do you import pipeline?
What do you need to remember?
from quantopian.pipeline import Pipeline
That the first pipeline is lower case p and the second pipeline (the import) is upper case.
In quantopian if you get,
AttributeError: ‘function’ object has no attribute ‘to_execution_plan’
what does this mean?
It happens when you forget to put the parentheses on a function to convert it into a method.
By not putting parentheses you are just passing through the function code,
When using pipeline what does it mean to add a ‘factor’ and/or ‘filter’ represent?
Adding factors means that you’re adding numerical values.
Adding filters means adding a boolean value.
What pipeline method do you need to use to stop certain securities from entering the pipeline you have defined?
your_pipeline_name.set_screen()
Why are pipelines used in quantopian?
Pipelines query all the data at the beginning of the backtest.
Using a pipeline improves data fetch and calculation performance.
The output of a pipeline is pandas dataframe with columns for each piece of data.
What does alphalens do?
It is a python package to analyze the performance of alpha factors.
Using alphalens will help make your strategies more robust and less prone to overfitting.
Alphalens needs to applied to signal not the strategy!