Skip to content

Commit

Permalink
80 character limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Richardson committed Apr 24, 2019
1 parent 600e1d6 commit 7f417ea
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 46 deletions.
87 changes: 57 additions & 30 deletions gui.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ open Pervasives
(* Make market around this value *)
let tutorial_value = 100

(* TUTORIAL ALGORITHM TO ENSURE PLAYER MAKES PROGRESS TOWARDS THE PROPER INTERVAL *)
(* TUTORIAL ALGORITHM TO ENSURE PLAYER MAKES PROGRESS TOWARDS THE PROPER
INTERVAL *)

type trade_feedback = Low | High | BigSpread | Okay

(* [check_good_interval bid ask] is an option of either None or Some bool option. If interval is bad, then None. If interval is good but spread too large then
Some false . Otherwise Some true. *)
(* [check_good_interval bid ask] is an option of either None or Some bool
option. If interval is bad, then None. If interval is good but spread
too large then Some false . Otherwise Some true. *)
let check_good_interval (bid:int) (ask:int) =
if (bid <= tutorial_value )
&& (ask >= tutorial_value )
Expand All @@ -20,7 +22,8 @@ let check_good_interval (bid:int) (ask:int) =
&& ((ask - bid) >= 15)then Some false
else None

(* [eval_trade bid ask] is a string message that acts as feedback to a [bid] and [ask]. *)
(* [eval_trade bid ask] is a string message that acts as feedback to a
[bid] and [ask]. *)
let eval_trade bid ask =
match (check_good_interval bid ask) with
| Some x ->
Expand Down Expand Up @@ -77,29 +80,41 @@ let rec tutorial_fsm unit =

let tutorial_preamble unit =
ANSITerminal.erase Screen;
ANSITerminal.print_string [ANSITerminal.magenta] "~ TUTORIAL INTRODUCTION ~\n";
ANSITerminal.print_string [ANSITerminal.yellow] ("The goal of this game is to make a market for traders who want to buy and sell " ^ "CamlCoin. \nFor now, suppose we tell you that the true value of CamlCoin is $10.\n");
ANSITerminal.print_string [ANSITerminal.yellow] ("Your goal is to continuously provide bid/ask spreads and hopefully make a profit on " ^ "your spread.\n");
ANSITerminal.print_string [ANSITerminal.yellow] ("We use the notation 'set x y' to mean you, the marketmaker, will BUY at x and SELL at y \n \n");
ANSITerminal.print_string [ANSITerminal.yellow] ("This means traders will BUY at y and SELL at x! \n \n");
ANSITerminal.print_string [ANSITerminal.yellow] ("Suppose your market is 'set 20 40'. \n \nIn this case, the sell price of $20 is greater than the intrinsic value. \nSellers get a great deal! They can sell something worth $10 for"
^ "$20. Expect a lot of sells. Adjust your interval downwards.\n");
ANSITerminal.print_string [ANSITerminal.yellow] ("\nSuppose your market is 'set 5 8'. \n \nIn this case, the buy price $8 is much less than " ^ "the intrinsic value of $10. Buys are getting a bargain! Expect a lot of buys. Adjust your interval upwards.");
ANSITerminal.print_string [ANSITerminal.yellow] ("\n\nSuppose your market is 'set 9 11'. \n\nYour market is good! With some variance, " ^ "buyers will buy at $11 which is very close to the actual price. Sellers will sell at $9. Expect roughly even " ^ " buyers and sellers. \nYou will make $11 - $9 = $2 per transaction.");
ANSITerminal.print_string [ANSITerminal.yellow] ("\n\n>>>> Starting tutorial <<<< ");
ANSITerminal.print_string [ANSITerminal.yellow] ("\nNow you try. We won't tell you the actual price... \n");
ANSITerminal.print_string [ANSITerminal.magenta]
"~ TUTORIAL INTRODUCTION ~\n";
ANSITerminal.print_string [ANSITerminal.yellow]
("The goal of this game is to make a market for traders who want to buy and sell " ^ "CamlCoin. \nFor now, suppose we tell you that the true value of CamlCoin is $10.\n");
ANSITerminal.print_string [ANSITerminal.yellow]
("Your goal is to continuously provide bid/ask spreads and hopefully make a profit on " ^ "your spread.\n");
ANSITerminal.print_string [ANSITerminal.yellow]
("We use the notation 'set x y' to mean you, the marketmaker, will BUY at x and SELL at y \n \n");
ANSITerminal.print_string [ANSITerminal.yellow]
("This means traders will BUY at y and SELL at x! \n \n");
ANSITerminal.print_string [ANSITerminal.yellow]
("Suppose your market is 'set 20 40'. \n \nIn this case, the sell price of $20 is greater than the intrinsic value. \nSellers get a great deal! They can sell something worth $10 for"
^ "$20. Expect a lot of sells. Adjust your interval downwards.\n");
ANSITerminal.print_string [ANSITerminal.yellow]
("\nSuppose your market is 'set 5 8'. \n \nIn this case, the buy price $8 is much less than " ^ "the intrinsic value of $10. Buys are getting a bargain! Expect a lot of buys. Adjust your interval upwards.");
ANSITerminal.print_string [ANSITerminal.yellow]
("\n\nSuppose your market is 'set 9 11'. \n\nYour market is good! With some variance, " ^ "buyers will buy at $11 which is very close to the actual price. Sellers will sell at $9. Expect roughly even " ^ " buyers and sellers. \nYou will make $11 - $9 = $2 per transaction.");
ANSITerminal.print_string [ANSITerminal.yellow]
("\n\n>>>> Starting tutorial <<<< ");
ANSITerminal.print_string [ANSITerminal.yellow]
("\nNow you try. We won't tell you the actual price... \n");
tutorial_fsm ();
()

(* Text to display *)

let preamble unit =
ANSITerminal.erase Above;
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.yellow] "Welcome! \n";
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.yellow]
"Welcome! \n";
ANSITerminal.(print_string [black; yellow]
"Welcome to the CamlCoin exchange! Here you will practice your maket making skills \n"); ()
"Welcome to the CamlCoin exchange! Here you will practice your maket making skills \n"); ()
let display_help unit =
ANSITerminal.print_string [ANSITerminal.red; ANSITerminal.blue] ("The list of possible commands are: ");
ANSITerminal.print_string [ANSITerminal.red; ANSITerminal.blue]
("The list of possible commands are: ");
ANSITerminal.print_string [ANSITerminal.red; ANSITerminal.yellow] ("
set [bid] [ask] \n
inventory \n
Expand All @@ -110,23 +125,35 @@ let display_help unit =
()

let introduction unit =
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("Today, you are the sole market maker of a coin called CamelCoin. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("You will be making a market for several traders in USD. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("You are competing with other high frequency trading firms such as Citadel, Jane Street and Optiver, so be fast! \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("Type in 'help' for a list of commands or 'tutorial' to begin the tutorial \n" );
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("We will assume familiarity, so let us begin! \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("Today, you are the sole market maker of a coin called CamelCoin. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("You will be making a market for several traders in USD. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("You are competing with other high frequency trading firms such as Citadel, Jane Street and Optiver, so be fast! \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("Type in 'help' for a list of commands or 'tutorial' to begin the tutorial \n" );
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("We will assume familiarity, so let us begin! \n");
display_help ();
ANSITerminal.print_string [ANSITerminal.red] ("The true cost of a CamelCoin is equal to the answer of the following question: \n \n");
ANSITerminal.print_string [ANSITerminal.red]
("The true cost of a CamelCoin is equal to the answer of the following question: \n \n");
()

let introduction_adv unit =
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("Today, you are the sole market maker of a coin called CamelCoin. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("You will be making a market for several traders in USD. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("You are competing with other high frequency trading firms, so be fast! \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("Type in 'help' for a list of commands or 'tutorial' to begin the tutorial \n" );
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green] ("We will assume familiarity, so let us begin! \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("Today, you are the sole market maker of a coin called CamelCoin. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("You will be making a market for several traders in USD. \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("You are competing with other high frequency trading firms, so be fast! \n");
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("Type in 'help' for a list of commands or 'tutorial' to begin the tutorial \n" );
ANSITerminal.print_string [ANSITerminal.black; ANSITerminal.green]
("We will assume familiarity, so let us begin! \n");
display_help ();
ANSITerminal.print_string [ANSITerminal.red] ("Simulating dice rolls....\n");
ANSITerminal.print_string [ANSITerminal.red] ("Each trader has rolled a dice.\n");
ANSITerminal.print_string [ANSITerminal.red]
("Each trader has rolled a dice.\n");
ANSITerminal.print_string [ANSITerminal.red] ("You rolled a : \n \n");
()
2 changes: 2 additions & 0 deletions stats.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ let trade_freq market trader =
let prnt = ["hits = "^(string_of_int hits); "lifts = "^(string_of_int lifts)]
in List.iter print_string prnt

(**[chebyshevs_var var] Uses the normal variance of a float list, and
calculates chebyshevs variance *)
let chebyshevs_var var =
match var with
|0. -> 0.
Expand Down
51 changes: 35 additions & 16 deletions test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ let make_last_three_lsr_test
(name : string)
(lst : int list)
(expected_output : float ): test =
name >:: (fun _ -> assert_equal expected_output (floor (Stats.last_three_lsr lst))
name >::
(fun _ -> assert_equal expected_output (floor (Stats.last_three_lsr lst))
~printer: (pp_float))

let last_three_lsr_tests = [
Expand All @@ -90,7 +91,8 @@ let make_get_graph_test
(market : Marketmaker.t )
(trader : Trader.t)
(expected_output : graph_data ): test =
name >:: (fun _ -> assert_equal expected_output (Stats.get_graph market trader))
name >::
(fun _ -> assert_equal expected_output (Stats.get_graph market trader))


let get_graph_tests = [
Expand All @@ -114,7 +116,8 @@ let make_linear_reg_cheat_test
(market : Marketmaker.t )
(dice : Stats.dice_data)
(expected_output : float ): test =
name >:: (fun _ -> assert_equal expected_output (Stats.linear_reg_cheat market dice ))
name >:: (
fun _ -> assert_equal expected_output (Stats.linear_reg_cheat market dice ))


let linear_reg_cheat_tests = [
Expand All @@ -125,7 +128,8 @@ let make_chebyshevs_var_test
(name : string)
(var : float)
(expected_output : float ): test =
name >:: (fun _ -> assert_equal expected_output (floor (Stats.chebyshevs_var var))
name >::
(fun _ -> assert_equal expected_output (floor (Stats.chebyshevs_var var))
~printer: (pp_float))

let chebyshevs_var_tests = [
Expand Down Expand Up @@ -173,11 +177,18 @@ let test1_transaction = {
order_type = "lift"
}
let trader_tests = [
"init_trader" >:: (fun _ -> assert_equal ({id = "1"; hidden_number = 20; avg_buy_value = 0; profit = 0; cash = 1000000; inventory = 0;
orderbook = {transactions = []; buys = 0; sells = 0}}) (init_trader 20 "1")) ;
"make_trade_test" >:: (fun _ -> assert_equal (None) (make_trade sample_trader sample_transaction));
"make_trade_dumb_test 1" >:: (fun _ -> assert_equal (None) (make_trade_dumb sample_trader sample_transaction));
"make_transaction test 1" >:: (fun _-> assert_equal test1_transaction (make_transaction 2 42 4242 "lift"))
"init_trader" >::
(fun _ -> assert_equal ({id = "1"; hidden_number = 20;
avg_buy_value = 0; profit = 0; cash = 1000000; inventory = 0;
orderbook = {transactions = []; buys = 0; sells = 0}})
(init_trader 20 "1")) ;
"make_trade_test" >::
(fun _ -> assert_equal (None) (make_trade sample_trader sample_transaction));
"make_trade_dumb_test 1" >::
(fun _ -> assert_equal (None)
(make_trade_dumb sample_trader sample_transaction));
"make_transaction test 1" >::
(fun _-> assert_equal test1_transaction (make_transaction 2 42 4242 "lift"))
]
(*Marketmaker's tests stuff*)
let samplem_bidask = {
Expand Down Expand Up @@ -263,7 +274,9 @@ let make_get_question_test
(name : string)
(data : Parse.t )
(expected_output : int ): test =
name >:: (fun _ -> assert_equal expected_output (Parse.get_question data |> String.length)
name >::
(fun _ -> assert_equal expected_output (
Parse.get_question data |> String.length)
~printer: pp_int)


Expand Down Expand Up @@ -296,8 +309,10 @@ let make_get_nth_situation_test


let get_nth_situation_tests = [
make_get_nth_situation_test "get_nth_situation test 1: 0th" 0 fermi_json oth_situation;
make_get_nth_situation_test "get_nth_situation test 1: 1st" 1 fermi_json first_situation;
make_get_nth_situation_test "get_nth_situation test 1: 0th"
0 fermi_json oth_situation;
make_get_nth_situation_test "get_nth_situation test 1: 1st"
1 fermi_json first_situation;
]

let make_get_event_from_situation_test
Expand All @@ -310,8 +325,10 @@ let make_get_event_from_situation_test


let get_event_from_situation_tests = [
make_get_event_from_situation_test "get_event_from_situation test 1: 0th" oth_situation "Flash Crash, all stocks are down";
make_get_event_from_situation_test "get_event_from_situation test 1: 1st" first_situation "Interest rates decrease";
make_get_event_from_situation_test "get_event_from_situation test 1: 0th"
oth_situation "Flash Crash, all stocks are down";
make_get_event_from_situation_test "get_event_from_situation test 1: 1st"
first_situation "Interest rates decrease";
]

let make_get_effect_from_situation_test
Expand All @@ -323,8 +340,10 @@ let make_get_effect_from_situation_test


let get_effect_from_situation_tests = [
make_get_effect_from_situation_test "get_effect_from_situation test 1: 0th" oth_situation (Some ("decrease", "10%"));
make_get_effect_from_situation_test "get_effect_from_situation test 1: 1st" first_situation (Some ("increase", "2%"));
make_get_effect_from_situation_test "get_effect_from_situation test 1: 0th"
oth_situation (Some ("decrease", "10%"));
make_get_effect_from_situation_test "get_effect_from_situation test 1: 1st"
first_situation (Some ("increase", "2%"));
]

let make_get_intro_test
Expand Down

0 comments on commit 7f417ea

Please sign in to comment.