{"action":"created","comment":{"url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments/29288847","id":29288847,"diff_hunk":"@@ -0,0 +1,152 @@\n+package ch.epfl.ts.evaluation\n+\n+import scala.language.postfixOps\n+import scala.collection.mutable.{Map => MMap, MutableList => MList}\n+import scala.concurrent.duration.{DurationInt, DurationLong}\n+import scala.concurrent.duration.FiniteDuration\n+import akka.actor.{ActorRef, Cancellable}\n+import ch.epfl.ts.component.{ComponentRegistration, Component, ComponentRef}\n+import ch.epfl.ts.data._\n+import ch.epfl.ts.data.Currency._\n+\n+/**\n+  * Evaluates the performance of traders by total returns, volatility, draw down and sharpe ratio\n+  *\n+  * To use this class, redirect all previous connections into and out of the trader to\n+  * instances of this class.\n+  *\n+  * Note that a component providing Quote data must be connected to this component in order for\n+  * it to maintain a price table and calculate profit/loss correctly.\n+  *\n+  * @param trader the reference to the trader component\n+  * @param traderId the id of the trader\n+  * @param initial the initial seed money\n+  * @param currency currency of the initial seed money\n+  * @param period the time period to compute performance\n+  */\n+class Evaluator(trader: ComponentRef, traderId: Long, initial: Double, currency: Currency, period: FiniteDuration) extends Component {\n+  // for usage of scheduler\n+  import context._\n+\n+  private var schedule: Cancellable = null\n+  private val wallet = MMap[Currency, Double](currency -> initial)\n+  private val returnsList = MList[Double]()\n+  private val priceTable = MMap[(Currency, Currency), Double]()\n+\n+  private var lastValue = initial\n+  private var maxProfit = 0.0\n+  private var maxLoss = 0.0\n+\n+  //TODO find appropriate value for risk free rate\n+  val riskFreeRate = 0.03\n+  def totalReturns: Double = value() / initial\n+  def volatility: Double = computeVolatility\n+  def drawdown: Double = maxLoss / initial\n+  def sharpeRatio: Double = (totalReturns - riskFreeRate) / volatility\n+\n+  /**\n+   * Redirects out-going connections to the trader","path":"ts/src/main/scala/ch/epfl/ts/evaluation/Evaluator.scala","position":48,"original_position":48,"commit_id":"5144e4e166847859f43181e5628e0e2ab7900efc","original_commit_id":"5144e4e166847859f43181e5628e0e2ab7900efc","user":{"login":"liufengyun","id":754633,"avatar_url":"https://avatars.githubusercontent.com/u/754633?v=3","gravatar_id":"","url":"https://api.github.com/users/liufengyun","html_url":"https://github.com/liufengyun","followers_url":"https://api.github.com/users/liufengyun/followers","following_url":"https://api.github.com/users/liufengyun/following{/other_user}","gists_url":"https://api.github.com/users/liufengyun/gists{/gist_id}","starred_url":"https://api.github.com/users/liufengyun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liufengyun/subscriptions","organizations_url":"https://api.github.com/users/liufengyun/orgs","repos_url":"https://api.github.com/users/liufengyun/repos","events_url":"https://api.github.com/users/liufengyun/events{/privacy}","received_events_url":"https://api.github.com/users/liufengyun/received_events","type":"User","site_admin":false},"body":"Yes, Evaluator doesn't output data to other components. Currently I assume Evaluator just runs a strategy against a standard dataset and stops, output metrics in the console.","created_at":"2015-04-28T21:08:44Z","updated_at":"2015-04-28T21:08:44Z","html_url":"https://github.com/merlinND/TradingSimulation/pull/33#discussion_r29288847","pull_request_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments/29288847"},"html":{"href":"https://github.com/merlinND/TradingSimulation/pull/33#discussion_r29288847"},"pull_request":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33","id":33996892,"html_url":"https://github.com/merlinND/TradingSimulation/pull/33","diff_url":"https://github.com/merlinND/TradingSimulation/pull/33.diff","patch_url":"https://github.com/merlinND/TradingSimulation/pull/33.patch","issue_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/33","number":33,"state":"open","locked":false,"title":"Backtest trading strategies","user":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-23T21:08:14Z","updated_at":"2015-04-28T21:08:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a629e935d229b9d0748d56c2d9fb69bc2a506275","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33/commits","review_comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33/comments","review_comment_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments{/number}","comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/33/comments","statuses_url":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/5144e4e166847859f43181e5628e0e2ab7900efc","head":{"label":"merlinND:backtest","ref":"backtest","sha":"5144e4e166847859f43181e5628e0e2ab7900efc","user":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"repo":{"id":31139958,"name":"TradingSimulation","full_name":"merlinND/TradingSimulation","owner":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/merlinND/TradingSimulation","description":"TradingSimulation is a modular framework designed for back-testing trading strategies.","fork":true,"url":"https://api.github.com/repos/merlinND/TradingSimulation","forks_url":"https://api.github.com/repos/merlinND/TradingSimulation/forks","keys_url":"https://api.github.com/repos/merlinND/TradingSimulation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/merlinND/TradingSimulation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/merlinND/TradingSimulation/teams","hooks_url":"https://api.github.com/repos/merlinND/TradingSimulation/hooks","issue_events_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/events{/number}","events_url":"https://api.github.com/repos/merlinND/TradingSimulation/events","assignees_url":"https://api.github.com/repos/merlinND/TradingSimulation/assignees{/user}","branches_url":"https://api.github.com/repos/merlinND/TradingSimulation/branches{/branch}","tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/tags","blobs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/refs{/sha}","trees_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/{sha}","languages_url":"https://api.github.com/repos/merlinND/TradingSimulation/languages","stargazers_url":"https://api.github.com/repos/merlinND/TradingSimulation/stargazers","contributors_url":"https://api.github.com/repos/merlinND/TradingSimulation/contributors","subscribers_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscribers","subscription_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscription","commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/commits{/sha}","git_commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/commits{/sha}","comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/comments{/number}","issue_comment_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/comments{/number}","contents_url":"https://api.github.com/repos/merlinND/TradingSimulation/contents/{+path}","compare_url":"https://api.github.com/repos/merlinND/TradingSimulation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/merlinND/TradingSimulation/merges","archive_url":"https://api.github.com/repos/merlinND/TradingSimulation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/merlinND/TradingSimulation/downloads","issues_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues{/number}","pulls_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls{/number}","milestones_url":"https://api.github.com/repos/merlinND/TradingSimulation/milestones{/number}","notifications_url":"https://api.github.com/repos/merlinND/TradingSimulation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/merlinND/TradingSimulation/labels{/name}","releases_url":"https://api.github.com/repos/merlinND/TradingSimulation/releases{/id}","created_at":"2015-02-21T20:34:13Z","updated_at":"2015-04-27T15:06:40Z","pushed_at":"2015-04-28T20:59:17Z","git_url":"git://github.com/merlinND/TradingSimulation.git","ssh_url":"git@github.com:merlinND/TradingSimulation.git","clone_url":"https://github.com/merlinND/TradingSimulation.git","svn_url":"https://github.com/merlinND/TradingSimulation","homepage":"","size":4700,"stargazers_count":2,"watchers_count":2,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":8,"forks":1,"open_issues":8,"watchers":2,"default_branch":"master"}},"base":{"label":"merlinND:master","ref":"master","sha":"8411e18cf381c76d65ab842be81e9463b2243ac8","user":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"repo":{"id":31139958,"name":"TradingSimulation","full_name":"merlinND/TradingSimulation","owner":{"login":"merlinND","id":5563370,"avatar_url":"https://avatars.githubusercontent.com/u/5563370?v=3","gravatar_id":"","url":"https://api.github.com/users/merlinND","html_url":"https://github.com/merlinND","followers_url":"https://api.github.com/users/merlinND/followers","following_url":"https://api.github.com/users/merlinND/following{/other_user}","gists_url":"https://api.github.com/users/merlinND/gists{/gist_id}","starred_url":"https://api.github.com/users/merlinND/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/merlinND/subscriptions","organizations_url":"https://api.github.com/users/merlinND/orgs","repos_url":"https://api.github.com/users/merlinND/repos","events_url":"https://api.github.com/users/merlinND/events{/privacy}","received_events_url":"https://api.github.com/users/merlinND/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/merlinND/TradingSimulation","description":"TradingSimulation is a modular framework designed for back-testing trading strategies.","fork":true,"url":"https://api.github.com/repos/merlinND/TradingSimulation","forks_url":"https://api.github.com/repos/merlinND/TradingSimulation/forks","keys_url":"https://api.github.com/repos/merlinND/TradingSimulation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/merlinND/TradingSimulation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/merlinND/TradingSimulation/teams","hooks_url":"https://api.github.com/repos/merlinND/TradingSimulation/hooks","issue_events_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/events{/number}","events_url":"https://api.github.com/repos/merlinND/TradingSimulation/events","assignees_url":"https://api.github.com/repos/merlinND/TradingSimulation/assignees{/user}","branches_url":"https://api.github.com/repos/merlinND/TradingSimulation/branches{/branch}","tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/tags","blobs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/refs{/sha}","trees_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/{sha}","languages_url":"https://api.github.com/repos/merlinND/TradingSimulation/languages","stargazers_url":"https://api.github.com/repos/merlinND/TradingSimulation/stargazers","contributors_url":"https://api.github.com/repos/merlinND/TradingSimulation/contributors","subscribers_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscribers","subscription_url":"https://api.github.com/repos/merlinND/TradingSimulation/subscription","commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/commits{/sha}","git_commits_url":"https://api.github.com/repos/merlinND/TradingSimulation/git/commits{/sha}","comments_url":"https://api.github.com/repos/merlinND/TradingSimulation/comments{/number}","issue_comment_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues/comments{/number}","contents_url":"https://api.github.com/repos/merlinND/TradingSimulation/contents/{+path}","compare_url":"https://api.github.com/repos/merlinND/TradingSimulation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/merlinND/TradingSimulation/merges","archive_url":"https://api.github.com/repos/merlinND/TradingSimulation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/merlinND/TradingSimulation/downloads","issues_url":"https://api.github.com/repos/merlinND/TradingSimulation/issues{/number}","pulls_url":"https://api.github.com/repos/merlinND/TradingSimulation/pulls{/number}","milestones_url":"https://api.github.com/repos/merlinND/TradingSimulation/milestones{/number}","notifications_url":"https://api.github.com/repos/merlinND/TradingSimulation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/merlinND/TradingSimulation/labels{/name}","releases_url":"https://api.github.com/repos/merlinND/TradingSimulation/releases{/id}","created_at":"2015-02-21T20:34:13Z","updated_at":"2015-04-27T15:06:40Z","pushed_at":"2015-04-28T20:59:17Z","git_url":"git://github.com/merlinND/TradingSimulation.git","ssh_url":"git@github.com:merlinND/TradingSimulation.git","clone_url":"https://github.com/merlinND/TradingSimulation.git","svn_url":"https://github.com/merlinND/TradingSimulation","homepage":"","size":4700,"stargazers_count":2,"watchers_count":2,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":8,"forks":1,"open_issues":8,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33"},"html":{"href":"https://github.com/merlinND/TradingSimulation/pull/33"},"issue":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/issues/33"},"comments":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/merlinND/TradingSimulation/statuses/5144e4e166847859f43181e5628e0e2ab7900efc"}}}}