<UserControl x:Class="TradeBlotter.Views.MomentumView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
						 xmlns:vw="clr-namespace:TradeBlotter.Views"												 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
						 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
						xmlns:local="clr-namespace:TradeBlotter.UIUtils"			
			      xmlns:wpfx="http://schemas.xceed.com/wpf/xaml/toolkit"						 
             mc:Ignorable="d" 
             d:DesignHeight="340" d:DesignWidth="768">
	<UserControl.Resources>
		<Style x:Key="MomentumItemStyle" TargetType="{x:Type telerik:RadGridView}">
		</Style>
	</UserControl.Resources>
	<wpfx:BusyIndicator Name="BusyBar" IsBusy="{Binding Path=BusyIndicator}" BusyContent="{Binding Path=BusyContent}">
		<Grid  Background="LightGray">
			<DockPanel>
				<Grid DockPanel.Dock="Left" Margin="0,2,4,2">
					<Grid.ColumnDefinitions>
						<ColumnDefinition Width="2*" />
						<ColumnDefinition Width="3" />
						<ColumnDefinition Width="11*" />
					</Grid.ColumnDefinitions>
					<Grid.RowDefinitions>
						<RowDefinition Height="35" />
						<RowDefinition Height="3" />
						<RowDefinition Height="1*" />
						<RowDefinition Height="3" />
						<RowDefinition Height="2*" />
					</Grid.RowDefinitions>
					<Label Grid.Row="0" Grid.Column="2" FontFamily="Arial" Content="{Binding Path=Title}" HorizontalAlignment="Center" FontSize="20"></Label>
					<StackPanel Orientation="Vertical" Grid.Row="2" Grid.RowSpan="5" Grid.Column="0">
						<Label Content="Date" HorizontalAlignment="Left" ></Label>
						<telerik:RadDatePicker SelectableDateStart="{Binding Path=SelectableDateStart}" SelectableDateEnd="{Binding Path=SelectableDateEnd}" VerticalAlignment="Top"  HorizontalAlignment="Left" SelectedDate="{Binding Path=SelectedDate,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
						<Label Content="Parameters" HorizontalAlignment="Left" ></Label>
						<ComboBox ItemsSource="{Binding Path=Parameters, Mode=OneWay}" SelectedItem="{Binding Path=SelectedParameter, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" >
							<ComboBox.ItemsPanel>
								<ItemsPanelTemplate>
									<VirtualizingStackPanel/>
								</ItemsPanelTemplate>
							</ComboBox.ItemsPanel>
						</ComboBox>
						<TextBox  Height="24" MinWidth="80" HorizontalAlignment="Stretch" IsReadOnly="true" Text="{Binding Path=ParameterValue, Mode=OneWay,ValidatesOnDataErrors=True, UpdateSourceTrigger=LostFocus}" Validation.ErrorTemplate="{x:Null}"/>
						<Button Margin="0,2" Content="Find Candidates" HorizontalAlignment="Stretch" Command="{Binding Path=RunCommand}"></Button>
						<Label Content="Monitor Interval" HorizontalAlignment="Left" ></Label>
						<ComboBox ItemsSource="{Binding Path=MonitorIntervals, Mode=OneWay}" SelectedItem="{Binding Path=SelectedMonitorInterval, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}" >
							<ComboBox.ItemsPanel>
								<ItemsPanelTemplate>
									<VirtualizingStackPanel/>
								</ItemsPanelTemplate>
							</ComboBox.ItemsPanel>
						</ComboBox>
						<Button Margin="0,2" IsEnabled="{Binding Path=CanMonitor}" Content="{Binding Path=MonitorStatus}" HorizontalAlignment="Stretch" Command="{Binding Path=Monitor}"></Button>

						<Button Content="Load Trade File" HorizontalAlignment="Stretch" Command="{Binding Path=LoadFile}"></Button>
					</StackPanel>
					<DockPanel x:Name="DockPanel1" Grid.Row="2" Grid.Column="2">
						<telerik:RadGridView SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" ItemContainerStyle="{StaticResource MomentumItemStyle}" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" ItemsSource="{Binding Path=AllItems, ValidatesOnDataErrors=True}" AutoGenerateColumns="False" >
							<telerik:RadContextMenu.ContextMenu>
								<telerik:RadContextMenu x:Name="GridContextMenu" StaysOpen="False" ItemsSource="{Binding CandidateMenuItems}">
									<telerik:RadContextMenu.ItemContainerStyle>
										<Style TargetType="telerik:RadMenuItem">
											<Setter Property="Header" Value="{Binding Text}" />
											<Setter Property="Command" Value="{Binding MenuItemClickedCommand}" />
											<Setter Property="StaysOpenOnClick" Value="False" />
										</Style>
									</telerik:RadContextMenu.ItemContainerStyle>
								</telerik:RadContextMenu>
							</telerik:RadContextMenu.ContextMenu>
							<telerik:RadGridView.Columns>
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Symbol" DataMemberBinding="{Binding Path=Symbol}" >
									<telerik:GridViewColumn.ToolTipTemplate>
										<DataTemplate >
											<StackPanel Orientation="Horizontal" >
												<TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:MomentumView}},Path=DataContext.CompanyDescription}"/>
											</StackPanel>
										</DataTemplate>
									</telerik:GridViewColumn.ToolTipTemplate>
								</telerik:GridViewDataColumn>
								<telerik:GridViewDataColumn IsReadOnly="True" Header="AnalysisDate" DataMemberBinding="{Binding Path=AnalysisDate,StringFormat='{}{0:MM/dd/yyyy}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="CumReturn252" DataMemberBinding="{Binding Path=CumReturn252,StringFormat='{}{0:P2}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="DayCount" DataMemberBinding="{Binding Path=DayCount,StringFormat='{}{0:N0}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="IDIndicator" DataMemberBinding="{Binding Path=IDIndicator,StringFormat='{}{0:N2}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="MaxDrawdown" DataMemberBinding="{Binding Path=MaxDrawdown,StringFormat='{}{0:P2}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="MaxUpside" DataMemberBinding="{Binding Path=MaxUpside,StringFormat='{}{0:P2}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="PE" DataMemberBinding="{Binding Path=PE,StringFormat='{}{0:N2}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Beta" DataMemberBinding="{Binding Path=Beta,StringFormat='{}{0:N2}'}" >
									<telerik:GridViewColumn.ToolTipTemplate>
										<DataTemplate >
											<StackPanel Orientation="Horizontal" >
												<TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:MomentumView}},Path=DataContext.BetaDescription}"/>
											</StackPanel>
										</DataTemplate>
									</telerik:GridViewColumn.ToolTipTemplate>
								</telerik:GridViewDataColumn>
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Velocity" DataMemberBinding="{Binding Path=Velocity,StringFormat='{}{0:P2}'}" >
									<telerik:GridViewColumn.ToolTipTemplate>
										<DataTemplate >
											<StackPanel Orientation="Horizontal" >
												<TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:MomentumView}},Path=DataContext.VelocityDescription}"/>
											</StackPanel>
										</DataTemplate>
									</telerik:GridViewColumn.ToolTipTemplate>
								</telerik:GridViewDataColumn>									
								<telerik:GridViewDataColumn IsReadOnly="True" Header="ZacksRank" DataMemberBinding="{Binding Path=ZacksRank}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Volume" DataMemberBinding="{Binding Path=Volume,StringFormat='{}{0:N2}'}" />
								<telerik:GridViewDataColumn IsReadOnly="True" Header="Return1D" DataMemberBinding="{Binding Path=Return1D,StringFormat='{}{0:N3}'}" />
							</telerik:RadGridView.Columns>
						</telerik:RadGridView>
					</DockPanel>
					<DockPanel x:Name="DockPanel2" Grid.Row="4" Grid.Column="2" >
						<Grid>
							<Grid x:Name="PositionsView" Visibility="Visible">
								<!--<Border Background="Blue"/>-->
								<telerik:RadGridView SelectedItem="{Binding Path=SelectedPosition, Mode=TwoWay}" ItemContainerStyle="{StaticResource MomentumItemStyle}" AlternationCount="2" AlternateRowBackground="Bisque" ShowGroupFooters="True" ShowColumnFooters="True" ItemsSource="{Binding Path=AllPositions, ValidatesOnDataErrors=True}" AutoGenerateColumns="False" >
									<telerik:RadContextMenu.ContextMenu>
										<telerik:RadContextMenu x:Name="PositionGridContextMenu" StaysOpen="False" ItemsSource="{Binding PositionsMenuItems}">
											<telerik:RadContextMenu.ItemContainerStyle>
												<Style TargetType="telerik:RadMenuItem">
													<Setter Property="Header" Value="{Binding Text}" />
													<Setter Property="Command" Value="{Binding MenuItemClickedCommand}" />
													<Setter Property="StaysOpenOnClick" Value="False" />
												</Style>
											</telerik:RadContextMenu.ItemContainerStyle>
										</telerik:RadContextMenu>
									</telerik:RadContextMenu.ContextMenu>
									<telerik:RadGridView.Columns>
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Symbol" DataMemberBinding="{Binding Path=Symbol}" >
											<telerik:GridViewColumn.ToolTipTemplate>
												<DataTemplate >
													<StackPanel Orientation="Horizontal" >
														<TextBlock Background="LemonChiffon" MaxWidth="1000" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type vw:MomentumView}},Path=DataContext.CompanyDescriptionSelectedPosition}"/>
													</StackPanel>
												</DataTemplate>
											</telerik:GridViewColumn.ToolTipTemplate>
										</telerik:GridViewDataColumn>
											<telerik:GridViewDataColumn IsReadOnly="True" Header="Slot" DataMemberBinding="{Binding Path=SlotAsString}" />		
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Purchased" DataMemberBinding="{Binding Path=PurchaseDate,StringFormat='{}{0:MM/dd/yyyy}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Sold" DataMemberBinding="{Binding Path=SellDate,StringFormat='{}{0:MM/dd/yyyy}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Days" DataMemberBinding="{Binding Path=DaysHeld}" />										
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Shares" DataMemberBinding="{Binding Path=Shares,StringFormat='{}{0:N0}'}" >
											<telerik:GridViewDataColumn.AggregateFunctions>
												<local:MomentumPositionSumFunctionShares />
											</telerik:GridViewDataColumn.AggregateFunctions>
										</telerik:GridViewDataColumn>
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Purch.Price" DataMemberBinding="{Binding Path=PurchasePrice,StringFormat='{}{0:C}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="CurrentPrice" >
											<telerik:GridViewDataColumn.CellTemplate>
												<DataTemplate>
													<TextBlock Text="{Binding Path=CurrentPrice,StringFormat='{}{0:C}'}" Foreground="{Binding Path=CurrentPriceColor}"/>
												</DataTemplate>
											</telerik:GridViewDataColumn.CellTemplate>
										</telerik:GridViewDataColumn>
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Updated" DataMemberBinding="{Binding Path=LastUpdated,StringFormat='{}{0:MM/dd/yyyy HH:mm:ss}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Exposure">
											<telerik:GridViewDataColumn.AggregateFunctions>
												<local:MomentumPositionSumFunctionExposure />
											</telerik:GridViewDataColumn.AggregateFunctions>
											<telerik:GridViewDataColumn.CellTemplate>
												<DataTemplate>
													<TextBlock Text="{Binding Path=ActiveExposure,StringFormat='{}{0:C}'}" Foreground="{Binding Path=ActiveExposureColor}"/>
												</DataTemplate>
											</telerik:GridViewDataColumn.CellTemplate>											
										</telerik:GridViewDataColumn>
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Mkt.Value">
											<telerik:GridViewDataColumn.AggregateFunctions>
												<local:MomentumPositionSumFunctionMarketValue />
											</telerik:GridViewDataColumn.AggregateFunctions>
											<telerik:GridViewDataColumn.CellTemplate>
												<DataTemplate>
													<TextBlock Text="{Binding Path=ActiveMarketValue,StringFormat='{}{0:C}'}" Foreground="{Binding Path=ActiveMarketValueColor}"/>
												</DataTemplate>
											</telerik:GridViewDataColumn.CellTemplate>
										</telerik:GridViewDataColumn>
										<telerik:GridViewDataColumn IsReadOnly="True" Header="GainLoss"  >
											<telerik:GridViewDataColumn.AggregateFunctions>
												<local:MomentumPositionSumFunctionGainLoss />
											</telerik:GridViewDataColumn.AggregateFunctions>
											<telerik:GridViewDataColumn.CellTemplate>
												<DataTemplate>
													<TextBlock Text="{Binding Path=GainLoss,StringFormat='{}{0:C}'}" Foreground="{Binding Path=GainLossColor}"/>
												</DataTemplate>
											</telerik:GridViewDataColumn.CellTemplate>											
										</telerik:GridViewDataColumn>		
										<telerik:GridViewDataColumn IsReadOnly="True" Header="GainLoss(%)" >
										<telerik:GridViewDataColumn.AggregateFunctions>
											<local:MomentumPositionSumFunctionGainLossPcnt />
										</telerik:GridViewDataColumn.AggregateFunctions>
											<telerik:GridViewDataColumn.CellTemplate>
												<DataTemplate>
													<TextBlock Text="{Binding Path=GainLossPcnt,StringFormat='{}{0:P3}'}" Foreground="{Binding Path=GainLossPcntColor}"/>
												</DataTemplate>
											</telerik:GridViewDataColumn.CellTemplate>
										</telerik:GridViewDataColumn>
										<telerik:GridViewDataColumn IsReadOnly="True" Header="IDIndicator" DataMemberBinding="{Binding Path=IDIndicator,StringFormat='{}{0:N2}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="MaxDrawdown" DataMemberBinding="{Binding Path=MaxDrawdown,StringFormat='{}{0:P2}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="MaxUpside" DataMemberBinding="{Binding Path=MaxUpside,StringFormat='{}{0:P2}'}" />										
										<telerik:GridViewDataColumn IsReadOnly="True" Header="PE" DataMemberBinding="{Binding Path=PE,StringFormat='{}{0:N2}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Beta" DataMemberBinding="{Binding Path=Beta,StringFormat='{}{0:N2}'}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="ZacksRank" DataMemberBinding="{Binding Path=ZacksRank}" />
										<telerik:GridViewDataColumn IsReadOnly="True" Header="Volume" DataMemberBinding="{Binding Path=Volume,StringFormat='{}{0:N0}'}" />
									</telerik:RadGridView.Columns>
								</telerik:RadGridView>
							</Grid>
							<!--<Grid x:Name="ConfigurationView" Visibility="Hidden">
								<Border Background="Red"/>
							</Grid>-->
						</Grid>						
					</DockPanel>
					<GridSplitter Panel.ZIndex="1" Background="LightBlue" ResizeDirection="Rows" Grid.Column="2" Grid.Row="3" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"/>
					<GridSplitter Grid.Row="1" Grid.Column="1" ResizeDirection="Columns" Grid.RowSpan="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="LightBlue" Width="3"/>
				</Grid>
			</DockPanel>
		</Grid>
	</wpfx:BusyIndicator>
</UserControl>

