Sunday, May 15, 2011

Initial Micro Predication Market Ticker Interface

Micro Prediction Market Project Ticker Interface

Baby steps toward a much larger project


In the prior posting, I published a first draft of the overall architecture for a program that will take the bids on issues from people on a small team, and product a dynamic accounting of the relative values of issues under consideration.

Here is a little background on the genesis of this application. My day-job is with a large not-for-profit health-care provider, and like many organizations, the needs greatly outweigh the resources to accomplish everything. We have a fantastic team of System Engineers who support the server environment. We have a very dynamic Information Services environment (the hospital has made a commitment to differentiate themselves in the market and provide better support to patients through the use of technology). Given this, it is a struggle to pick which internal projects will have the greatest impact on letting us move forward faster. For example, which will have a greater impact on our end-user community: harvesting dead server objects in Active Directory that were missed through human error on the part of our Operations Group, or updating the virtual server templates that we use to generate new servers? The organic way of deciding would be to put all of the choices in front of everyone, and after debate back and forth, we might pick the best option, or we might pick the option that the most passionate and persuasive person on the team advocates. What I wanted was a quantitative way of measuring the wisdom of the small crowd of coworkers that I have, with a minimum of bias.

So was born the idea of the Micro Prediction Market Project. The very first iteration of this project was to test the concept using a spreadsheet. We collected all of the potential ideas into a list. In order to minimize the possibility that an outcome would be “gamed”, we enforced scarcity of resources by giving each team member a number of “credits ($1) that were equal to 50% of the number of total issues. I created a template for the spreadsheet, and emailed a blank to each individual team member, asking them over that week to consider the projects listed, and apply credits to those issues that they thought would have the greatest impact (either by freeing up our time so that we could focus on other issues, or by directly providing beneficial impact to our user community). Once the team filled out their individual spreadsheets, they emailed them back to me, and I cut and pasted the results into an overview sheet, whose results fed up into a dashboard sheet in the Excel workbook that gave the results. I presented the results at a team meeting, and it was well received. We elected the top three issues to work on (Updating Server Templates, Re-arranging our work environment to align with team work-flow, and re-organizing Active Directory Organization Unit structures for servers.)

So far, so good, but this process is highly inefficient and problematic. It requires a lot of manual work to update and present the spreadsheet, and the only way to deliver the results is highly static. Much better would be a web page that gave the results, and even better would be a client-server voting system that allowed a more dynamic means of evaluating issues as the environment changes. What I really hoped to provide was a marketplace of ideas that would constantly provide the best ideas from the team, ranked according to the value to the organization. Hence, the Micro Prediction Market Project (or MP2X for short) was born.

As with all things more complex, the path to a complete application starts with a baby step. I decided the first step would be to display the results of voting as a web page. I’m calling the web display of the voting results the “Ticker Interface”, though I’m going to title the web page “Market Overview”. I would take the spreadsheet that was developed, and save the pages of the workbook as .csv files (using the most basic utf-8 encoding). I have decided to start working with the Python programming language (version 2.7 instead of 3.2, due to the greater availability of stable modules and libraries written for the older version). It has many advantages, and allows me to develop code usable for web applications fairly easily.

For this article, I’ve abstracted the issues, values, and names of coworkers in the input data for the .csv files. I’m more interested in sharing the process, inputs, code, and output of this basic Python program. Here are the three worksheets that I’m using as source data for the Ticker Interface:


Market Indicator
Value
Total Market Value
$5000
Total Market Money Supply
$4000
Market Liquidity
$2500
Total Outstanding Share Value
$1500


Price
Name
Shares Issued
Short Description
$10
AAA
100
Mock Issue Number 1
$11
BBB
90
Mock Issue Number 2
$12
CCC
80
Mock Issue Number 3
$13
DDD
70
Mock Issue Number 4
$14
EEE
60
Mock Issue Number 5
$15
FFF
50
Mock Issue Number 6
$16
GGG
40
Mock Issue Number 7
$17
HHH
30
Mock Issue Number 8
$18
JJJ
20
Mock Issue Number 9
$19
KKK
10
Mock Issue Number 10

Name
Portfolio Value
Total Shares
Top Issue Held
Bob
$60
250
Mock Issue Number 1
Mary
$50
240
Mock Issue Number 3
Sally
$40
230
Mock Issue Number 5
John
$30
220
Mock Issue Number 7
Jack
$20
210
Mock Issue Number 9
Jill
$10
200
Mock Issue Number 10


All of the information in these tables is currently calculated in a Microsoft Excel 2010 workbook. In this posting, I have used fake values that are designed to be easily identified as I developed the code to present the results as a web page (so don’t try to reverse-engineer the tabulation method, it won’t work out).

In order to print to an HTML file (which I’m calling MP2XtickerOut.html and storing in the !/usr/bin/python directory of an Amazon EC2 Micro Instance of Ubuntu Linux), I’m using a combination of simple Print commands (which is sending text to standard output), as well as leveraging the HTML.py module. To import the .csv files, I’m using the Python CSV Module, treating all of the files as simple binary data inputs.

I wrote this application using the Python Eric IDE available in Ubuntu. Here is my source code:

# MP2X Ticker Interface
# Python 2.7.1+
# MP2X Ticker Interface version V.01
# Python script to convert from CSV to HTML, line by line, into a basic table format.

# Jon A. Hallgrimsson <http://codehallgrim.blogspot.com/>

import csv
import sys

if len(sys.argv) < 2:
  print "Usage: ./csv-html.py MP2XCSVmarketindicator.csv MP2XtickerOutput.html"
  exit(0)

# Open source CSV file MP2XCSVmarketindicator.csv for reading
reader = csv.reader(open(sys.argv[1]))

# Create the HTML file
f_html = open(sys.argv[2],"wb");
f_html.write('<title><Micro Prediction Market Project></title>')

print '<body bgcolor="#ffffff">'
print '<h1 align="center"><b><font size="5">'
print '<p>Micro Prediction Market Ticker</p></b></font><b><font size="3">'
print '<p>Market Overview</p>'
print '<p align="center">'

f_html.write('<table>')

for row in reader: # Reads a row from CSV
  f_html.write('<tr>');# Create new row in table
  for column in row: # For each column.
    f_html.write('<td>' + column + '</td>');
  f_html.write('</tr>')

f_html.write('</table>')

print '<center>'

# Second Table - Issue Values

if len(sys.argv) < 2:
  print "Usage: ./csv-html.py MP2XCSVIssueValues.csv MP2XtickerOut.html"
  exit(0)

# Open source CSV file MP2XCSVIssueValues.csv for reading
reader = csv.reader(open(sys.argv[1]))

f_html.write('<table>')

# Create the HTML file
f_html = open(sys.argv[2],"wb");
f_html.write('<title><Issue Values></title>')

for row in reader: # Reads a row from CSV
  f_html.write('<tr>');# Create new row in table
  for column in row: # For each column.
    f_html.write('<td>' + column + '</td>');
  f_html.write('</tr>')

f_html.write('</table>')

print '<center>'

# Third Table - LeaderBoard

if len(sys.argv) < 2:
  print "Usage: ./csv-html.py MP2XCSVLeaderBoard.csv MP2XtickerOut.html"
  exit(0)

# Open source CSV file MP2XCSVLeaderBoard.csv for reading
reader = csv.reader(open(sys.argv[1]))

f_html.write('<table>')

# Create the HTML file
f_html = open(sys.argv[2],"wb");
f_html.write('<title><LeaderBoard></title>')

for row in reader: # Reads a row from CSV
  f_html.write('<tr>');# Create new row in table
  for column in row: # For each column.
    f_html.write('<td>' + column + '</td>');
  f_html.write('</tr>')

f_html.write('</table>')

</body></html>'

 # Close all files in Python

 f.close()
This code writes out the contents of the CSV files ( MP2XCSVmarketindicator.csv, MP2XCSVIssueValues.csv, and MP2XCSVLeaderBoard.csv ), reading them one row at a time and sending each row to the HTML page (MP2XtickerOut.html ). A shell script on the Ubuntu web server will then copy MP2XtickerOut.html to the web services folder on the server, for display on the monitors above where our team works.

Here is what the output looks like:

Micro Prediction Market Project

Market Overview

Market Indicator

Value

Total Market Value

$5000

Total Market Money Supply

$4000

Market Liquidity

$2500

Total Outstanding Share Value

$1500

 

Issue Values

Price

Name

Shares Issued

Short Description

$10

AAA

100

Mock Issue Number 1

$11

BBB

90

Mock Issue Number 2

$12

CCC

80

Mock Issue Number 3

$13

DDD

70

Mock Issue Number 4

$14

EEE

60

Mock Issue Number 5

$15

FFF

50

Mock Issue Number 6

$16

GGG

40

Mock Issue Number 7

$17

HHH

30

Mock Issue Number 8

$18

JJJ

20

Mock Issue Number 9

$19

KKK

10

Mock Issue Number 10

 

Leader Board

Name

Portfolio Value

Total Shares

Top Issue Held

Bob

$60

250

Mock Issue Number 1

Mary

$50

240

Mock Issue Number 3

Sally

$40

230

Mock Issue Number 5

John

$30

220

Mock Issue Number 7

Jack

$20

210

Mock Issue Number 9

Jill

$10

200

Mock Issue Number 10


This is a primitive beginning to an ambitious project. I’m looking forward to creating a better formatted HTML page for the ticker interface, as well as a way of abandoning the Excel spreadsheet completely, moving to a complete web based voting and tracking system.

I’m interested in any input, ideas, or constructive criticism you may have. I’m excited about a more productive future!

No comments:

Post a Comment