Advertisement
Guest User

Untitled

a guest
Sep 19th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.86 KB | None | 0 0
  1. import std.stdio;
  2.  
  3. struct Portfolio {
  4.   double[string] data;
  5.   // ...
  6. }
  7.  
  8. struct HedgeRecommendation {
  9.   string recommendation;
  10.   this(int) {
  11.     recommendation = "Sell, the market is rigged";
  12.   }
  13. }
  14.  
  15. struct Analyzer {
  16.   immutable(Portfolio) portfolio;
  17.   this(ref immutable(Portfolio) portfolio) {
  18.     this.portfolio = portfolio;
  19.   }
  20.  
  21.   HedgeRecommendation createHedge() {
  22.     auto result = HedgeRecommendation(1);
  23.     //...
  24.     return result;
  25.   }
  26. }
  27.  
  28. Portfolio readPortfolio(string id) {
  29.   // read portfolio from database
  30.   return Portfolio([ "IBM" : 100.0, "SPY" : 300.0 ]);
  31. }
  32.  
  33. HedgeRecommendation getHedgeRecommendation(string portfolioId) {
  34.   auto portfolio = cast(immutable)readPortfolio(portfolioId);
  35.   auto analyzer = Analyzer(portfolio);
  36.   return analyzer.createHedge();
  37. }
  38.  
  39. void main() {
  40.   writeln(getHedgeRecommendation("1234"));
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement