Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- struct Portfolio {
- double[string] data;
- // ...
- }
- struct HedgeRecommendation {
- string recommendation;
- this(int) {
- recommendation = "Sell, the market is rigged";
- }
- }
- struct Analyzer {
- immutable(Portfolio) portfolio;
- this(ref immutable(Portfolio) portfolio) {
- this.portfolio = portfolio;
- }
- HedgeRecommendation createHedge() {
- auto result = HedgeRecommendation(1);
- //...
- return result;
- }
- }
- Portfolio readPortfolio(string id) {
- // read portfolio from database
- return Portfolio([ "IBM" : 100.0, "SPY" : 300.0 ]);
- }
- HedgeRecommendation getHedgeRecommendation(string portfolioId) {
- auto portfolio = cast(immutable)readPortfolio(portfolioId);
- auto analyzer = Analyzer(portfolio);
- return analyzer.createHedge();
- }
- void main() {
- writeln(getHedgeRecommendation("1234"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement