January 2020
Intermediate to advanced
532 pages
13h 31m
English
To simplify this design, we can parameterize the type of the thing being traded. What is the thing? We can leverage the abstract type here. The supertype of Stock is Equity, while the supertype of Equity is Investment. Since we want to keep the code generic and buying/selling investment products is similar, we can choose to accept any type that is a subtype of Investment:
struct SingleTrade{T <: Investment} <: Trade type::LongShort instrument::T quantity::Int price::Float64end
Now, we have defined a new type called SingleTrade, where the underlying instrument has a type, T, where T can be any subtype of Investment. At this point, we can create trades with different kinds of instruments:
These objects actually have ...
Read now
Unlock full access