Applying Corporate Actions#
A series of simple examples are provided showing how to retrieve data with applied Corporate Actions.
Original Price History#
Market Data is generally retrieved by querying the specified database, table and symbol.
def trades():
pt = otq.Passthrough().tick_type('TRD')
graph = otq.Graph(pt)
return graph
result = otq.run(trades,
http_address=rest_url,access_token=access_token,
output_mode="pandas",
start=datetime(2024,1,3,9,30,0),
end = datetime(2024,1,3,9,31,0),
timezone='America/New_York',
symbols='US_COMP_SAMPLE::CSCO' # Specifies the [Database]::[Symbol]
)
Adjusted Price History#
To adjust price history for corporate actions, the CorpActions
object can be added to the graph.
Adjustments can modify both the Price and Quantity fields of a price history, so the adjust_rule
attribute is used to specify if:
Modifying Price Fields (
adjust_rule='PRICE'
)Modifying Quantity Fields (
adjust_rule='SIZE'
)
The fields to just are specified with the fields
attribute.
Different corporate actions can be applied to the dataset based on additional attributes of the object, such as applying splits
with apply_split=True
.
The run
method must also be modified to include the symbol_date
attribute.
def trades_adjusted():
pt = otq.Passthrough(fields='PRICE,SIZE').tick_type('TRD')
add_fields = otq.AddFields(fields='ORIG_PRICE=PRICE, ORIG_SIZE=SIZE')
adjust_price = otq.CorpActions(fields='PRICE',adjust_rule='PRICE',apply_split=True)
adjust_size = otq.CorpActions(fields='SIZE',adjust_rule='SIZE',apply_split=True)
graph = otq.Graph(pt >> add_fields >> adjust_price >> adjust_size)
return graph
query = trades_adjusted()
result = otq.run(query,
http_address=rest_url,access_token=access_token,
output_mode="pandas",
start=datetime(2024,1,10,0,0,0),
end = datetime(2024,1,17,0,0,0),
timezone='Europe/London',
symbols='LSE_SAMPLE::DKE',
symbol_date = datetime.today()
)